﻿using Sorting.App.Models.Enum;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Modules.TaskMan.Views
{
    public class StoreViewItemHelper : DependencyObject
    {
        public event PropertyChangedEventHandler PropertyChanged;
    }
    /// <summary>
    /// StoreViewItem.xaml 的交互逻辑
    /// </summary>
    public partial class StoreViewItem : UserControl
    {
        public StoreViewItem()
        {
            InitializeComponent();
        }

        public string WardNameValue
        {
            get { return (string)GetValue(WardNameProperty); }
            set { SetValue(WardNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty WardNameProperty =
            DependencyProperty.Register("WardNameValue", typeof(string), typeof(StoreViewItem), new PropertyMetadata(new PropertyChangedCallback(onWardNameChanged)));
        static void onWardNameChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is string newValue)
            {
                var control = sender as StoreViewItem;
                control.WardName.Content = args.NewValue.ToString();
            }
        }

        /// <summary>
        /// 储位名称
        /// </summary>
        public string LocNameValue
        {
            get { return (string)GetValue(LocNameProperty); }
            set { SetValue(LocNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty LocNameProperty =
            DependencyProperty.Register("LocNameValue", typeof(string), typeof(StoreViewItem), new PropertyMetadata(new PropertyChangedCallback(onLocNameChanged)));
        static void onLocNameChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is string newValue)
            {
                var control = sender as StoreViewItem;
                control.LocName.Content = args.NewValue.ToString();
            }
        }


        /// <summary>
        /// 已经扫描的数量
        /// </summary>
        public int ScanNumValue
        {
            get { return (int)GetValue(ScanNumProperty); }
            set { SetValue(ScanNumProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty ScanNumProperty =
            DependencyProperty.Register("ScanNumValue", typeof(int), typeof(StoreViewItem), new PropertyMetadata(0,new PropertyChangedCallback(onScanNumChanged)));
        static void onScanNumChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is int newValue)
            {
                var control = sender as StoreViewItem;
                control.HasScanNum.Content = args.NewValue.ToString();
            }
        }



        /// <summary>
        /// 已经入筐的数量
        /// </summary>
        public int HasInVenNumValue
        {
            get { return (int)GetValue(HasInVenNumProperty); }
            set { SetValue(HasInVenNumProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty HasInVenNumProperty =
            DependencyProperty.Register("HasInVenNumValue", typeof(int), typeof(StoreViewItem), new PropertyMetadata(0,new PropertyChangedCallback(onHasInVenChanged)));
        static void onHasInVenChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is int newValue)
            {
                var control = sender as StoreViewItem;
                control.HasInFinishNum.Content = args.NewValue.ToString();
            }
        }


        /// <summary>
        /// 库存比例
        /// </summary>
        public double VenRateValue
        {
            get { return (double)GetValue(VenRateProperty); }
            set { SetValue(VenRateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty VenRateProperty =
            DependencyProperty.Register("VenRateValue", typeof(double), typeof(StoreViewItem), new PropertyMetadata((double)0,new PropertyChangedCallback(onVenRateChanged)));
        static void onVenRateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is double newValue)
            {
                var control = sender as StoreViewItem;
                //进度条
                control.InvenRateBar.Value = (double)args.NewValue;
                //数值显示
                control.InvenRate.Content = Convert.ToUInt32(args.NewValue).ToString() + "%";
            }
        }




        /// <summary>
        /// 运行状态
        /// </summary>
        public EnumTaskState TaskRunStateValue
        {
            get { return (EnumTaskState)GetValue(TaskRunStateProperty); }
            set { SetValue(TaskRunStateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty TaskRunStateProperty =
            DependencyProperty.Register("TaskRunStateValue", typeof(EnumTaskState), typeof(StoreViewItem), new PropertyMetadata(new PropertyChangedCallback(onTaskRunStateChanged)));
      static  void onTaskRunStateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is EnumTaskState newValue)
            {
                var control = sender as StoreViewItem;
                switch (args.NewValue)
                {
                    case EnumTaskState.Running:
                        SetLineColor(control, "#f9c915");
                        break;
                    case EnumTaskState.Sucess:
                        SetLineColor(control,"#b0f510");
                        break;
                    case EnumTaskState.Fail:
                        SetLineColor(control,"#d61a22");
                        break;
                    default:
                        SetLineColor(control,"#4c7cea");
                        break;
                }
            }
        }


        
        /// <summary>
        /// 运行状态
        /// </summary>
        public EnumStockBoxState StoreStateValue
        {
            get { return (EnumStockBoxState)GetValue(StoreStateProperty); }
            set { SetValue(StoreStateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Labels.  This e nables animation, styling, binding, etc...
        public static readonly DependencyProperty StoreStateProperty =
            DependencyProperty.Register("StoreStateValue", typeof(EnumStockBoxState), typeof(StoreViewItem), new PropertyMetadata(new PropertyChangedCallback(onStoreStateChanged)));
      static  void onStoreStateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue is EnumStockBoxState newValue)
            {
                var control = sender as StoreViewItem;
                switch (args.NewValue)
                {
                    case EnumStockBoxState.NoFull:
                        SetDotColor( control,"#b0f510");
                        break;
                    case EnumStockBoxState.Full:
                        SetDotColor(control,"#f5120c");
                        break;
                    case EnumStockBoxState.Default:
                        SetDotColor(control, "#ff9f1a");
                        break;

                    default:
                        SetDotColor(control,"#c2c2c2");
                        break;
                }
            }
        }





        /// <summary>
        /// 设置边框颜色
        /// </summary>
        /// <param name="ColorString"></param>
        public static void SetLineColor (StoreViewItem control, string ColorString)
        {
            control.TopLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ColorString));
            control.BottomLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ColorString));
            control.LeftLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ColorString));
            control.RightLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ColorString));
        }



        /// <summary>
        /// 设置圆点颜色
        /// </summary>
        /// <param name="ColorString"></param>
        public static void SetDotColor (StoreViewItem control, string ColorString)
        {
            control.StoreStateDot.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ColorString));
        }
    }
}
